from json import JSONEncoder

from flask import Flask

from flask_mail import Mail

from .config import config
from flask_pymongo import PyMongo

from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()

mail = Mail()
mongo = PyMongo()

def create_app():
    app = Flask(__name__)
    #路由
    # 注册蓝图
    from app.routers import user_blueprint, verification_blueprint
    app.register_blueprint(user_blueprint)
    app.register_blueprint(verification_blueprint)
    #配置
    app.config.from_object(config['development'])
    config['development'].init_app(app)
    #数据库
    db.init_app(app)
    mail.init_app(app)
    mongo.init_app(app)



    #json编辑器
    #  替换默认的json编码器
    return app
